﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VehicleRecordSystem.util;

namespace VehicleRecordSystem.view
{
    /// <summary>
    /// Interaction logic for FuelPage.xaml
    /// </summary>
    public partial class FuelPage : Page
    {
        private static FuelPage instanse;

        public static FuelPage Instanse
        {
            get
            {
                if (instanse == null)
                {
                    instanse = new FuelPage();
                }

                return instanse;
            }
        }

        public FuelPage()
        {
            InitializeComponent();
        }

        private void btnFuelPageSave_Click(object sender, RoutedEventArgs e)
        {
            if (validate())
            {
                Single amount = Convert.ToSingle(txtAmount.Text);
                Single volume = Convert.ToSingle(txtVolume.Text);
                Single odometer = Convert.ToSingle(txtOdometer.Text);
                DateTime? date = datePickerDate.SelectedDate;
                String description = txtDescription.Text;
            }
        }

        private Boolean validate()
        {
            Boolean ok = true;

            if (string.IsNullOrEmpty(txtAmount.Text) || !VRSValidate.isNumberic(txtVolume.Text))
            {
                ok = false;
                GUI.changeBackgroundColorToError(txtAmount);
            }
            if (string.IsNullOrEmpty(txtVolume.Text) || !VRSValidate.isNumberic(txtVolume.Text))
            {
                ok = false;
                GUI.changeBackgroundColorToError(txtVolume);
            }
            if (string.IsNullOrEmpty(txtOdometer.Text) || !VRSValidate.isNumberic(txtOdometer.Text))
            {
                ok = false;
                GUI.changeBackgroundColorToError(txtOdometer);
            }
            if (string.IsNullOrEmpty(datePickerDate.SelectedDate.ToString()))
            {
                ok = false;
                GUI.changeBackgroundColorToError(datePickerDate);
            }
            if (string.IsNullOrEmpty(txtDescription.Text))
            {
                ok = false;
                GUI.changeBackgroundColorToError(txtDescription);
            }

            return ok;
        }

        private void changeBackgroundColorToNormal(object sender, RoutedEventArgs e)
        {
            GUI.changeBackgroundColorToNormal(sender);
        }

        private void validate_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox tb = (TextBox)sender;
            if (!VRSValidate.isNumberic(tb.Text))
            {
                GUI.changeBackgroundColorToError(tb);
            }
            else
            {
                GUI.changeBackgroundColorToNormal(tb);
            }
        }
    }
}
